package tsing.javase.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

public class Order {
    private String supplierName;
    private int quantity;
    private int month;

    public Order(String supplierName, int quantity, int month) {
        this.supplierName = supplierName;
        this.quantity = quantity;
        this.month = month;
    }

    public String getSupplierName() {
        return supplierName;
    }

    public int getQuantity() {
        return quantity;
    }

    public int getMonth() {
        return month;
    }

    public static void main(String[] args) {

        List<Order> orders = new ArrayList<>();
        orders.add(new Order("供应商A", 100, 1));
        orders.add(new Order("供应商B", 200, 1));
        orders.add(new Order("供应商C", 50, 2));
        orders.add(new Order("供应商D", 300, 2));
        orders.add(new Order("供应商E", 400, 3));
        orders.add(new Order("供应商F", 600, 3));

        Map<Integer, Set<String>> result = orders.stream()
                .collect(Collectors.groupingBy(Order::getMonth,
                        Collectors.mapping(Order::getSupplierName, Collectors.toSet())));

        System.out.println(result);






    }
}
